package com.lyj.io.module.data.controller;

import com.lyj.io.annotation.SysLogAnnotation;
import com.lyj.io.common.dto.IdsDto;
import com.lyj.io.common.utils.PageUtils;
import com.lyj.io.common.utils.R;
import com.lyj.io.module.data.entity.TabsEntity;
import com.lyj.io.module.data.service.TabsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 模型相关api
 * @author:liyajie
 * @createTime:2021/12/28 0:52
 * @version:1.0
 */
@Api(value = "SysMenuController", tags = "模型相关api")
@RestController
@RequestMapping("/api/v1/tabs")
public class TabsController {
    @Autowired
    private TabsService tabsService;

    /**
     * 查询模型列表
     * @author: liyajie
     * @date: 2021/12/29 15:14
     * @param params
     * @return com.lyj.io.common.utils.R
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("查询模型列表")
    @ApiOperation(value = "查询模型列表", notes = "查询模型列表")
    @PostMapping("/getTabslist")
    public R list(@RequestBody Map<String, Object> params) {
        PageUtils page = tabsService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 根据id查询模板
     * @author: liyajie
     * @date: 2021/12/29 15:24
     * @param id
     * @return com.lyj.io.common.utils.R
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("根据id查询模板")
    @ApiOperation(value = "根据id查询模板", notes = "根据id查询模板")
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        TabsEntity tabsEntity = tabsService.getById(id);
        return R.ok().put("data", tabsEntity);
    }

    /**
     * 新增模型
     * @author: liyajie
     * @date: 2021/12/29 15:32
     * @param tabsEntity
     * @return com.lyj.io.common.utils.R
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("新增模型")
    @ApiOperation(value = "新增模型", notes = "新增模型")
    @RequestMapping("/addTab")
    public R save(@RequestBody TabsEntity tabsEntity) {
        tabsService.save(tabsEntity);
        return R.ok();
    }

    /**
     * 更新模型
     * @author: liyajie
     * @date: 2021/12/29 15:45
     * @param tabsEntity
     * @return com.lyj.io.common.utils.R
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("更新模型")
    @ApiOperation(value = "更新模型", notes = "更新模型")
    @RequestMapping("/updateTab")
    public R update(@RequestBody TabsEntity tabsEntity) {
        tabsService.updateById(tabsEntity);
        return R.ok();
    }

    /**
     * 删除模型
     * @author: liyajie
     * @date: 2021/12/29 15:46
     * @param idsDto
     * @return com.lyj.io.common.utils.R
     * @exception:
     * @update:
     * @updatePerson:
     **/
    @SysLogAnnotation("删除模型")
    @ApiOperation(value = "删除模型", notes = "删除模型")
    @RequestMapping("/delTab")
    public R delete(@RequestBody IdsDto idsDto) {
        String ids = idsDto.getIds();
        tabsService.removeByIds(Arrays.asList(ids.split(",")));
        return R.ok();
    }

}
